<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>LG Energy Solution - {{$site_name}}</title>
    <meta name="description" content="Grasp technology trends, Bet on the future."/>
    <meta name="keywords"
          content="technology intelligence network,TMT, biomedicine, fintech, blockchain and investment"/>

    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport"/>
    <meta content="yes" name="apple-mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta content="telephone=no" name="format-detection"/>
    <link href="{{$app_host}}favicon.ico" rel="icon" type="image/x-icon"/>
    <link type="text/css" href="{{$style_host}}atw/style/css.css" rel="stylesheet"/>
    <script src="{{$style_host}}static/jquery/1.9.1/jquery.min.js"></script>
</head>

<style>
    body {
        background-color: #ffffff;
    }

    .search_header {
        width: 100%;
        background-color: #005cd8;
        text-align: center;
        padding: 50px 0;
    }

    .search_header div {
        width: 400px;
        margin: 0 auto;
    }

    .search_header a {
        color: #ffffff;
        font-size: 26px;
    }

    .search_header p {
        color: #ffffff;
        padding-top: 10px;
    }

    .search {
        width: 400px;
        margin: 20px auto 0 auto;
    }

    .search .email {
        border: 1px solid #333;
        width: 400px;
        padding: 20px 8px;
        font: 14px/1.25 Proxima Nova, Helvetica, Arial, sans-serif;
    }

    .search .but {
        width: 400px;
        display: flex;
        justify-content: space-between;
        padding-top: 30px;
    }

    .search .but .black {
        width: 180px;
        background-color: #000;
        color: #ffffff;
        padding: 16px 0;
        text-align: center;
        cursor: pointer;
        border: 0;
        border: 1px solid #000;
    }

    .search .but .black1 {
        background-color: #ffffff;
        color: #000;
    }

    @media only screen and (max-width: 1000px) {
        .search_header div {
            width: 80%;
        }

        .search {
            width: 80%;
            margin: 20px auto 0 auto;
        }

        .search .email {
            border: 1px solid #333;
            width: 100%;
            padding: 20px 8px;
            font: 14px/1.25 Proxima Nova, Helvetica, Arial, sans-serif;
        }

        .search .but {
            width: 100%;
            padding-top: 30px;
        }

        .search .but .black {
            width: 46%;
            background-color: #000;
            color: #ffffff;
            padding: 16px 0;
            text-align: center;
            cursor: pointer;
        }

        .search .but .black1 {
            background-color: #ffffff;
            color: #000;
        }
    }
</style>
<body>

<div class="search_header ">
    <div>
        <a href="/" class="fw700">Email Subscription</a>
        <p>Newsletters and emails are now available! Delivered on time, every weekday, to keep you up to date with North
            American business news.</p>
    </div>
</div>

<main>
    <form class="search" method="post">
        <input id="email" name="email" type="text" placeholder="Enter e-mail address" class="email">
        <div class="but">
            <input type="button" class="black black1" value="取消订阅" onclick="toEmail('cancel');">
            <input type="button" value="订阅" class="black" onclick="toEmail('on');">
            <!--<div class="black">订阅</div>-->
        </div>
    </form>
</main>

<script>
    /*$(".black").on('click', function () {
        let email = $("#email").val();
        if (!email) {
            alert('请输入你的电子邮件！')
            return false
        }

        // 执行订阅
        toEmail(email)
    })*/

    // 自动采集下一页
    function toEmail(type) {
        let email = $("#email").val();
        if (!email) {
            alert('请输入你的电子邮件！')
            return false
        }
        let emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
        if (!emailRegex.test(email)) {
            alert('请输入正确邮箱！！')
            return false;
        }

        let is_refresh = false
        let message = ''
        let url = type === 'cancel' ? '/ajax/cancel-rss' : '/ajax/on-rss';
        let atw_url = type === 'cancel' ? '/email-cancel.html' : '/email-ding.html';
        console.log('执行订阅', email);

        // 本地
        $.ajax({
            type: 'post',
            url: atw_url,
            // data: 'name=zhangsan&age=20'
            data: {email: email},
            //contentType: 'application/json',
            dataType: "json",
            // contentType: 'application/x-www-form-urlencoded',
            // 这个方法在请求发送前调用，可以用来做表单校验、用来做请求等待动画的调用
            /*beforeSend: function () {
                // 返回false是取消发送
                return false
            },*/
            // 会自动帮我们把返回的数据根据响应头设置的类型进行转换好（也就是会自动转成json对象）
            success: function (res) {
                console.log('执行结果', res)
                //alert(res.msg)
                message = res.msg
                if (res.code == 200) {
                    is_refresh = true
                }
            },
            // xhr是ajax对象
            error: function (xhr) {
            }
        });

        // 美新社
        $.ajax({
            type: 'post',
            url: 'https://www.nbwpress.com' + url,
            data: {email: email},
            contentType: 'application/x-www-form-urlencoded',
            //dataType: "jsonp",
            success: function (res) {
                console.log('返回成功的结果：', res)
                //alert(res.msg)
                message = res.msg
                if (res.code == 200) {
                    is_refresh = true
                    //window.location.href = window.location.href;
                }
            },
            // xhr是ajax对象
            error: function (xhr) {
                alert('邮件订阅失败！！')
            }
        });

        setTimeout(function () {
            alert(message)
            if (is_refresh) {
                window.location.href = window.location.href;
            }
        }, 1000)


        return false;
    }
</script>


</body>
</html>
